<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
</head>

<body>
  <div id="app">
    <cpn></cpn>

    <cpn>
      <div slot-scope="slot">
        <!-- slot.data就可以取到cpn1里面传递出来的data的值 -->
        <!-- <span v-for="(item, index) in slot.data" :key="index">{{item}} - </span> -->
        <span>{{slot.data.join(' - ')}}</span>
      </div>
    </cpn>

    <cpn>
      <template slot-scope="slot">
        <span v-for="(item, index) in slot.data" :key="index">{{item}} * </span>
      </template>
    </cpn>
  </div>

  <template id="cpn1">
    <div>
      <!-- data是个变量名 -->
      <slot :data="pLanguages">
        <ul>
          <li v-for="(item, index) in pLanguages" :key="index">{{item}}</li>
        </ul>
      </slot>
    </div>
  </template>
  <script src="../js/vue.js"></script>
  <script>
    const app = new Vue({
      el: "#app",
      data() {
        return {
          message: "Hello",
        };
      },
      components: {
        cpn: {
          template: "#cpn1",
          data() {
            return {
              pLanguages: ["JavaScript", "Java", "C++", "Python"],
            };
          },
        },
      },
    });
  </script>
</body>

</html>